package cn.fintecher.pangolin.service.business.model.request;

import cn.fintecher.pangolin.common.enums.BaseSelect;
import cn.fintecher.pangolin.common.enums.CaseDataStatus;
import cn.fintecher.pangolin.common.enums.CaseLeaveFlag;
import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import cn.fintecher.pangolin.service.business.model.BaseQueryRequest;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Objects;

/**
 * @Author wangxiangdong
 * @Description 结清案件查询request
 * @Date 2019/9/2 15:07
 **/
@Data
public class SettleCasesRequest extends BaseQueryRequest {

    @ApiModelProperty(notes = "记事本")
    private String comment;

    @ApiModelProperty(value = "催记数量")
    private Integer followRecordCount;

    @ApiModelProperty(value = "催收状态")
    private String collectStatus;

    @ApiModelProperty(value = "联系状态")
    private String contactStatus;

    @ApiModelProperty(value = "催收人员")
    private String collectorName;

    @ApiModelProperty(value = "催收机构code")
    private String departCode;

    @ApiModelProperty(value = "催记数量")
    private Integer telRecordCount;

    @ApiModelProperty(notes = "留案标识")
    private CaseLeaveFlag leaveFlag;

    public BooleanBuilder generateQueryBuilder() {
        BooleanBuilder booleanBuilder = generateBaseQueryBuilder();
        QCaseInfo caseInfo = QCaseInfo.caseInfo;
        booleanBuilder.and(caseInfo.caseDataStatus.in(CaseDataStatus.SETTLT, CaseDataStatus.REDUCE));
        if (Objects.nonNull(this.comment)) {
            booleanBuilder.and(caseInfo.comment.eq(this.comment));
        }
        if (Objects.nonNull(this.followRecordCount)) {
            booleanBuilder.and(caseInfo.telRecordCount.eq(this.followRecordCount));
        }
        if (Objects.nonNull(this.collectStatus)) {
            booleanBuilder.and(caseInfo.collectStatus.contains(this.collectStatus));
        }
        if (Objects.nonNull(this.leaveFlag)) {
            booleanBuilder.and(caseInfo.leaveFlag.eq(this.leaveFlag));
        }
        if (Objects.nonNull(this.collectorName)) {
            booleanBuilder.and(caseInfo.currentCollector.realName.like("%" + this.collectorName + "%"));
        }
        if (Objects.nonNull(this.departCode)) {
            booleanBuilder.and(caseInfo.currentCollector.department.departCode.like(this.departCode + "%"));
        }
        if (Objects.nonNull(this.telRecordCount)) {
            booleanBuilder.and(caseInfo.telRecordCount.eq(this.telRecordCount));
        }
        if (Objects.nonNull(this.contactStatus)) {
            booleanBuilder.and(caseInfo.contactStatus.contains(this.contactStatus));
        }
        return booleanBuilder;
    }

}
